//
//  ButtonSectionHeaderView.m
//  VTravel
//
//  Created by lanouhn on 16/8/2.
//  Copyright © 2016年 xiaoYu. All rights reserved.
//

#import "ButtonSectionHeaderView.h"

@interface ButtonSectionHeaderView ()

@property (nonatomic, assign) int *number;

@end

@implementation ButtonSectionHeaderView

- (instancetype)initWithButtonTitleArray:(NSArray *)buttonTitleArray{
    if (self = [super init]) {
        self.frame = CGRectMake(0, 0, kScreenWidth, 44);
        
        self.number = 0;
        for (int i = 0; i < buttonTitleArray.count; i++) {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectMake(kScreenWidth / buttonTitleArray.count * i, 0, kScreenWidth / buttonTitleArray.count, 44);
            button.tag = 1000 + i;
            [button setTitle:buttonTitleArray[i] forState:(UIControlStateNormal)];
            [button setTitleColor:[UIColor lightGrayColor] forState:(UIControlStateNormal)];
            [button addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
            
            self.view = [[UIView alloc] initWithFrame:CGRectMake(10, 40, kScreenWidth / buttonTitleArray.count - 20, 2)];
            self.view.backgroundColor = [UIColor grayColor];
            
            [button addSubview:self.view];
            [self addSubview:button];
        }
    }
    return self;
}

- (void)buttonAction:(UIButton *)sender{
    [sender setTitleColor:[UIColor orangeColor] forState:(UIControlStateNormal)];
    if (self.BtnClickedBlock) {
        self.BtnClickedBlock(sender.tag - 1000);
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
